package chess;

import java.awt.Image;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

import chesskers.GamePiece;
import chesskers.ImagePanel;
import chess.SpecialMove;

public abstract class ChessPiece extends GamePiece{
	
	public boolean isUnmoved;
	
	public SpecialMove sm;
	public boolean canSpecialMove;
	
	public ChessPiece(boolean black, int x_, int y_) {
		super(black, x_, y_);
		sm = new SpecialMove(); 
		isUnmoved = true;
	}
	
	public String getFilePath(){
		String filePath = "img/chesspieces/"+getName();
		
		if (isBlack){
			filePath += "_black";
		}else {
			filePath += "_white";
		}
		filePath += ".png";

		return filePath;
	}
	public GamePiece[][] moveTo(int x_, int y_, GamePiece[][] board) {
		return super.moveTo(x_, y_, board);
	}
	
	public GamePiece[][] attackTo(int x_, int y_, GamePiece[][] board){
		return moveTo(x_, y_, board);
	}
		
	public ArrayList<Point> getAttackPossibilities(GamePiece[][] board){
		
		ArrayList<Point> validAttacks = new ArrayList<Point>();
		
		for (int i = 0; i < attackPossibilities.length; i++){
			for (int j = 0; j < attackPossibilities[i].length; j++){
				try{
					if (board[x+attackPossibilities[i][j][0]][y+attackPossibilities[i][j][1]] != null) {
						if (board[x+attackPossibilities[i][j][0]][y+attackPossibilities[i][j][1]].isBlack != isBlack){
							validAttacks.add(new Point(x+attackPossibilities[i][j][0], y+attackPossibilities[i][j][1]));
						}
						break;
					}
				}catch( ArrayIndexOutOfBoundsException e ) {
					break;
				}
			}
		}
		return validAttacks;	
	}
	
	public int getRank() {
		return this.x;
	}
	public int getFile() {
		return this.y;
	}
	
	@Override
	public List<SpecialMove> getSpecialMovePossibilities() {
		return new ArrayList<SpecialMove>();
	}

	public GamePiece[][] SpecialMove(GamePiece[][] board, SpecialMove sm) {
		
		System.out.println("SPECIALMOVE USED");
		

		
		return board;
	}
}